<?if (isset($currentCategory)):?>
	<h1>Current category: <?=Html::chars($currentCategory['name'])?></h1>
<?else:?>
	<h1><?=ucfirst($section)?></h1>
<?endif?>
<table class="w100">
	<tr>
		<td class="w50 top paddingRight10" style="border-right: solid 1px #eee;">
			<?if (isset($currentCategory)):?>
				<p>
					<img src="/images/icons/smallFolderUp.png" width="32" height="32" alt="" class="middle"/>
					<?=Html::anchor(Request::$controller . ($currentCategory['parentId'] != 0 ? 'browse/' . $section . '/' . $currentCategory['parentId'] . '/' : 'browse/' . $section . '/'), '&uarr; Up category')?>
				</p>
			<?endif?>
			<hr />
			<?if (isset($categories) ? count($categories) : false):?>
				<ul class="list sortable">
				<?foreach($categories as $category):?>
					<?
						$name = isset($moduleSettings['title']['categories']) ? $category[$moduleSettings['title']['categories']] : $category['name'];
						$name = strip_tags($name);
						$name = strlen($name) > 30 ? substr($name, 0, 25) . '...' : $name;
					?>
					<li id="categories_<?=$category['id']?>">
						<table class="w100">
							<tr>
								<?if (
									isset($moduleSettings['sorting']['categories']) ?
									$moduleSettings['sorting']['categories'] :
									false
								):?>
									<td class="center" style="width: 30px;">
										<span class="sortable-handler"><img src="/images/icons/sort.png" class="middle" /></span>
									</td>
								<?endif?>
								<td>
									<img src="/images/icons/smallFolder.png" width="32" height="32" alt="" class="middle"/>
									<?=Html::anchor(Request::$controller . 'browse/' . $section . '/' . $category['id'] . '/', Html::chars($name))?>
								</td>
								<td style="width: 50px;" class="right">
									<?if (
										isset($moduleSettings['actions']['categories']['edit']) ?
										$moduleSettings['actions']['categories']['edit'] :
										true
									):?>
										<?=Html::anchor(Request::$controller . 'editCategory/' . $section . '/' . $category['id'] . '/', '<img src="/images/icons/edit.png" width="16" height="16" alt="Edit"/>')?>
									<?endif?>
									<?if (
										isset($moduleSettings['actions']['categories']['delete']) ?
										$moduleSettings['actions']['categories']['delete'] :
										true
									):?>
										&nbsp;
										<?=Html::anchor(Request::$controller . 'removeCategory/' . $section . '/' . $category['id'] . '/', '<img src="/images/icons/remove.png" width="16" height="16" alt="Delete folder"/>', array('onclick' => 'javascript:return confirm(CONFIRMATION_REMOVE)'))?>
									<?endif?>
								</td>
							</tr>
						</table>
					</li>
				<?endforeach?>
				</ul>
				<hr />
			<?endif?>
<!-- Add new category !-->
			<?if (
				(
					isset($moduleSettings['actions']['categories']['add']) ?
					$moduleSettings['actions']['categories']['add'] :
					true
				) ? (
					(
						isset($moduleSettings['levels']) ?
						(
							isset($currentCategory) ?
							$moduleSettings['levels'] > $allCategories[$currentCategory['id']]['level'] :
							$moduleSettings['levels'] > 0
						) :
						true
					) ?	(
						isset($categories) ?
						(
							isset($moduleSettings['max']['categories']) ?
							$moduleSettings['max']['categories'] > count($categories) :
							true
						) :
						false
					) : (
						false
					)
				) : (
					false
				)
			):?>
				<p>
					<img src="/images/icons/smallFolderAdd.png" width="32" height="32" alt="" class="middle"/>
					<?=Html::anchor(Request::$controller . 'addCategory/' . $section . '/' . (isset($parentId) ?  $parentId . '/' : ''), 'Add category')?>
				</p>
			<?endif?>
		</td>
		<td class="w50 top paddingLeft10">
			<?if (isset($items) ? count($items) : false):?>
				<hr />
				<ul class="list sortable">
				<?foreach($items as $item):?>
					<?
						$name = isset($moduleSettings['title']['items']) ? $item[$moduleSettings['title']['items']] : $item['name'];
						$name = strip_tags($name);
						$name = strlen($name) > 30 ? substr($name, 0, 25) . '...' : $name;
					?>
					<li id="items_<?=$item['id']?>">
							<table class="w100">
								<tr>
									<?if (
										isset($moduleSettings['sorting']['items']) ?
										$moduleSettings['sorting']['items'] :
										false
									):?>
										<td class="center" style="width: 30px;">
											<span class="sortable-handler"><img src="/images/icons/sort.png" class="middle"/></span>
										</td>
									<?endif?>
									<td>
										<?=Html::chars($name)?>
									</td>
									<td style="width: 50px;" class="right">
										<?=Html::anchor(Request::$controller . 'item/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/edit.png" width="16" height="16" alt="Edit"/>')?>
										<?if (
											isset($moduleSettings['actions']['items']['delete']) ?
											$moduleSettings['actions']['items']['delete'] :
											true
										):?>
											&nbsp;
											<?=Html::anchor(Request::$controller . 'removeItem/' . $section . '/' . $item['id'] . '/', '<img src="/images/icons/remove.png" width="16" height="16" alt="Delete folder"/>', array('onclick' => 'javascript:return confirm(CONFIRMATION_REMOVE)'))?>
										<?endif?>
									</td>
								</tr>
							</table>
						</li>
				<?endforeach?>
				</ul>
				<hr />
			<?endif?>
			<?if (
				(
					isset($moduleSettings['actions']['items']['add']) ?
					$moduleSettings['actions']['items']['add'] :
					true
				) ? (
						isset($items) ?
					(
						isset($moduleSettings['max']['items']) ?
						$moduleSettings['max']['items'] > count($items) :
						true
					) :
					false
				) : (
					false
				)
			):?>
				<?=Html::anchor(Request::$controller . 'addItem/' . $section . '/' . (isset($parentId) ?  $parentId . '/' : ''), 'Add item')?>
			<?endif?>
		</td>
	</tr>
</table>